#pragma once

#include "connection_manager.h"
#include "handler_pool.h"
#include <signal.h>

class TMultiHttpFileServer {
public:
    struct TOptions {
    public:
        TOptions(const std::string& path)
        : ConnectionQueueSize(10000)
        , PoolSize(10)
        , InternalBufferSize(1024 * 1024)
        , Path(path)
        , NetworkQueueSize(50)
        , Port("8080")
        {}

        bool IsValid() const
        {
            return !Path.empty();
        }

        unsigned int    ConnectionQueueSize;
        unsigned int    PoolSize;
        unsigned int    InternalBufferSize;
        std::string     Path;
        unsigned int    NetworkQueueSize;
        std::string     Port;
    };

    TMultiHttpFileServer();
    void Stop();
    void IoLoop(const TOptions& options);
    ~TMultiHttpFileServer();
private:
    bool Init(const TOptions& options);
    TConnectionManager  Connections;
    THandlerPool        Handlers;
    int                 Socket;
    struct sigaction    IgnoreSIGPIPE;
};
